package com.lottery.material.service.portal.transaction.impl;

import com.lottery.material.dao.transaction.TransactionRecordMapper;
import com.lottery.material.pojo.transaction.TransactionRecord;
import com.lottery.material.service.portal.transaction.TransactionRecordService;
import com.lottery.material.util.Const;
import com.lottery.material.vo.portal.transaction.TradeRecordStatisticsVo;
import com.lottery.material.vo.portal.transaction.TradeRecordVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Description:    交易记录服务接口
 * Author:         sunny
 * CreateDate:     2019-04-17 11:12
 */
@Service
public class TransactionRecordServiceImpl implements TransactionRecordService {

    @Autowired
    private TransactionRecordMapper transactionRecordMapper;

    @Override
    public TradeRecordStatisticsVo findTradeRecordStatistics(Map<String, String> reqParamMap) {
        Map<String, Object> map = new HashMap<>();
        map.putAll(reqParamMap);
        map.put("timeType", Integer.parseInt(reqParamMap.get("timeType")));
        TradeRecordStatisticsVo tradeRecordStatistics = transactionRecordMapper.findTradeRecordStatistics(map);
        map.put("indexStart", Const.PORTAL_PAGE * (Integer.parseInt(reqParamMap.get("page")) - 1));
        map.put("pageTotal", Const.PORTAL_PAGE);
        List<TradeRecordVo> tradeRecordVos = transactionRecordMapper.findTradeRecordByUserId(map);
        tradeRecordStatistics.setTradeRecordVos(tradeRecordVos);
        return tradeRecordStatistics;
    }

    /**
     * description: 根据对象参数查询记录数
     * author sunny
     * createDate 2019-04-17 上午 11:13
     *
     * @param transactionRecord
     * @return
     */
    @Override
    public Integer findCountByObject(TransactionRecord transactionRecord) {
        return transactionRecordMapper.findCountByObject(transactionRecord);
    }

    /**
     * description: 根据交易类型编号和文章id统计次数和总额
     * author sunny
     * createDate 2019-04-24 上午 9:48
     * @param transactionTypeCode
     * @param articleId
     * @return
     */
    @Override
    public Map<String, Object> findByTypeCodeAndArticleId(String transactionTypeCode, String articleId) {
        return transactionRecordMapper.findByTypeCodeAndArticleId(transactionTypeCode, articleId);
    }

    /**
     * description: 根据文章id分页查询付款查看文章明细
     * author sunny
     * createDate 2019-04-26 上午 11:30
     * @param paramMap
     * @return
     */
    @Override
    public List<Map<String, Object>> findPaymentDetailByArticleId(Map<String, Object> paramMap) {
        return transactionRecordMapper.findPaymentDetailByArticleId(paramMap);
    }

    /**
     * description: 根据文章id分页查询打赏文章明细
     * author sunny
     * createDate 2019-04-26 下午 1:42
     * @param paramMap
     * @return
     */
    @Override
    public List<Map<String, Object>> findRewardDetailByArticleId(Map<String, Object> paramMap) {
        return transactionRecordMapper.findRewardDetailByArticleId(paramMap);
    }

    /**
     * description: 根据用户id和文章id查询查看文章记录
     * author sunny
     * createDate 2019-04-24 下午 8:46
     * @param userId
     * @param articleId
     * @return
     */
    @Override
    public TransactionRecord findViewArticleByUserIdAndArticleId(String userId, String articleId) {
        return transactionRecordMapper.findViewArticleByUserIdAndArticleId(userId, articleId);
    }
}
